package com.toe.user.webapi.controller;


import com.toe.common.restful.JsonResult;
import com.toe.pojo.dto.user.PermissionAddDTO;
import com.toe.pojo.vo.user.UserAdminDetails;
import com.toe.user.service.UserAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/webapi/user-admin")
@Api(tags = "管理员模块")
public class UserAdminController {

    @Autowired
    private UserAdminService userAdminService;

    @ApiOperation("禁用管理员账号")
    @PostMapping("/delete")
    public JsonResult<Void> Ban(long id){
        userAdminService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("启用管理员账号")
    @PostMapping("/unban")
    public JsonResult<Void> unBan(long id){
        userAdminService.unDelete(id);
        return JsonResult.ok();
    }

    @ApiOperation("查看所有管理员账号")
    @PostMapping("/select")
    public JsonResult<List<UserAdminDetails>> selectAllAdmin(){
        List<UserAdminDetails> userAdminDetails = userAdminService.selectAllAdmin();
        return JsonResult.ok(userAdminDetails);
    }

    @ApiOperation("更新管理员权限")
    @PostMapping("/update")
    public JsonResult<Void> addAdminPermission(@RequestBody PermissionAddDTO permissionAddDTO){
        long roleId = permissionAddDTO.getRoleId();
        long[] permissionIds = permissionAddDTO.getPermissionIds();
        userAdminService.addAdminPermission(roleId, permissionIds);
        return JsonResult.ok();
    }
}

